
function workFlowDetail(formDTO,eventName){
	$.blockUI();
	
	var url = getWorkFlowURL();
	var formData = $("#"+formDTO).formSerialize();
	formData = formData + "&ajaxSource=ajaxRequest&_eventId="+eventName;
	if(remarksDialog != null){
		remarksDialog.dialog('close');
		remarksDialog.dialog('destroy');		
		$("#remarksDiv").empty().remove();
	}
	if(mapUserDialog != null){
		mapUserDialog.dialog('close');
		mapUserDialog.dialog('destroy');		
		$("#mapUsers").empty().remove();
	}
	if(rejectDocDialog != null){
		rejectDocDialog.dialog('close');
		rejectDocDialog.dialog('destroy');
		$("#rejectDocDiv").empty().remove();
	}
	if(vaultDetailsDialog!=null){
		vaultDetailsDialog.dialog('close');
		vaultDetailsDialog.dialog('destroy');
		$("#vaultDetailsDiv").empty().remove();
	}
	$.post(url,formData,function(data,response){
		$(mainContentDiv).empty().html(data);
		$.unblockUI(); 
	});
}

function goBack(eventType)
{
	$.blockUI();
	var url = getWorkFlowURL();
	$.post(url,{ajaxSource:'ajaxRequest',_eventId:eventType,mode:'embedded'},function(data){
		$("#remarksDiv").empty().html(data);
		$.unblockUI(); 
	});		
}


function submitDialog(){
	remarksDialog = $("#remarksDiv").dialog({
		autoOpen: false,
		height: 'auto',
		width: 300,
		modal: true,
		resizable: true,
		closeOnEscape: false,
		dialogClass : 'dialogClass remarksDialog',
		close: function(event,ui){
			var s3='';
			$("#remarks").val(s3);		
		}
	});
	var numOfDialog = $(".remarksDialog").length;
	if(numOfDialog > 1){
		$(".remarksDialog").first().empty().remove();
	}		
}

function openRemarksDialog()
{
	remarksDialog.dialog("open");
}
function viewDocumentWorkflow(docId,wfId,wfAction){
	$.blockUI();
	var url = getWorkFlowURL();
	$.post(url,{ajaxSource:'ajaxRequest',_eventId:'docDetail',docId:docId,mode:'embedded',wfId:wfId,workFlowAction:wfAction},function(data){
		$(mainContentDiv).empty().html(data);
		$.unblockUI(); 
	});
	
}
function submitDocument(eventName,eventType)
{
	$.blockUI();
	var url = getWorkFlowURL();
	$.post(url,{ajaxSource:'ajaxRequest',_eventId:'transitionState',mode:'embedded',activity:eventName,workflowActionType:eventType},function(data){
		$("#remarksDiv").empty().html(data);
		$.unblockUI(); 
	});		
}
function approveOrRejectDocument(formDTO,eventName){
	//showLoadingDialog("Sending...");
	$.blockUI();
	var url = getWorkFlowURL();
	var div = getDialogDiv();
	var formData = $("#"+formDTO).formSerialize();
	formData = formData + "&ajaxSource=ajaxRequest&mode=embedded&_eventId="+eventName;	
	$.post(url,formData,function(data,response){
		$("#"+div).empty().html(data);
		//hideLoadingDialog();
		$.unblockUI(); 
	});
}
function saveVaultDetails(formDTO,eventName){
	//showLoadingDialog("Sending...");
	$.blockUI();
	var url = getWorkFlowURL();
	var div = getDialogDiv();
	var formData = $("#"+formDTO).formSerialize();
	formData = formData + "&ajaxSource=ajaxRequest&mode=embedded&_eventId="+eventName;	
	$.post(url,formData,function(data,response){
		$("#"+div).empty().html(data);
		//hideLoadingDialog();
		$.unblockUI(); 
	});
}
// to be used from main memu vault details link
function updateVaultDetails(formDTO,eventName){
	//showLoadingDialog("Sending...");
	$.blockUI();
	var url = getWorkFlowURL();
	var div = getDialogDiv();
	var formData = $("#"+formDTO).formSerialize();
	formData = formData + "&ajaxSource=ajaxRequest&mode=embedded&_eventId="+eventName;	
	$.post(url,formData,function(data,response){
		$(mainContentDiv).empty().html(data);
		//hideLoadingDialog();
		$.unblockUI(); 
	});
}
function docDetail(uploadNewDocForm){
	//showLoadingDialog("Loading..",5000);
	$.blockUI();
	
	var url = getWorkFlowURL();
	var formData = $("#"+uploadNewDocForm).formSerialize();
	$.post(url,formData,{ajaxSource:'ajaxRequest',_eventId:'viewUploadDoc',mode:'embedded'},function(data,response){
		alert(response);
		$(mainContentDiv).empty().html(data);
		//hideLoadingDialog();
		$.unblockUI(); 
	});
}
function approveDocument(activityName)
{
	//showLoadingDialog("Loading..",5000);
	$.blockUI();
	var docId = $("#docId").val();
	var url = getWorkFlowURL();
	if(activityName=='mapUsers')
		{
		$.post(url,{ajaxSource:'ajaxRequest',_eventId:'transitionState',mode:'embedded',activity:activityName,docId:docId},function(data){
			
		$("#mapUsersDiv").empty().html(data);
		//hideLoadingDialog();
		$.unblockUI(); 
		});
	}
	else{
		$.post(url,{ajaxSource:'ajaxRequest',_eventId:'transitionState',mode:'embedded',activity:activityName,docId:docId},function(data){
			var numOfDialog = $("#vaultDetailsDiv").length;
			if(numOfDialog > 0)
				$("#vaultDetailsDiv").first().empty().remove();
		$("#vaultDiv").empty().html(data);
		//hideLoadingDialog();
		$.unblockUI(); 
		});	
	}
}

function createVaultDetailsDialog(){
	vaultDetailsDialog =
		$("#vaultDetailsDiv").dialog({
		autoOpen: false,
		height: 'auto',
		width: 800,
		modal: true,
		resizable: true,
		closeOnEscape: false,
		dialogClass : 'dialogClass vaultDetailsDialog1'
		});
	var numOfDialog = $(".vaultDetailsDialog1").length;
	if(numOfDialog > 1)
		$(".vaultDetailsDialog1").first().empty().remove();
	
}
function createrejectDocDialog(){
	rejectDocDialog = $("#rejectDocDiv").dialog({
	autoOpen: true,
	height: 'auto',
	width: 300,
	modal: true,
	resizable: true,
	closeOnEscape: false,
	dialogClass : 'dialogClass rejectDocDialog'
	});
	var numOfDialog = $(".rejectDocDialog").length;
	if(numOfDialog > 1)
		$(".rejectDocDialog").first().empty().remove();
	
}
function openVaultDetailsDialog()
{
	vaultDetailsDialog.dialog("open");
}
function openRejectDialog()
{
	rejectDocDialog.dialog("open");
}
function activateOrDeactivate(docId,currentStatus){
	$.blockUI();
	//var docId = $("#docId").val();
	var url = getWorkFlowURL();
	$.post(url,{ajaxSource:'ajaxRequest',_eventId:'activeOrDeactive',mode:'embedded',docId:docId,currentStatus:currentStatus},function(data,response){
		/*var temp = "";
		for(key in response){
			temp = temp + key + "--" + response[key] + "\n";
		}*/
		if(response.indexOf('success') != -1)
			alert("Successfully done.");
		$(mainContentDiv).empty().html(data);
		//hideLoadingDialog();
		$.unblockUI(); 
	});
}

function filterTaskList(id){
	var data = $("#" + id).formSerialize();
	
	$.blockUI();
	var url = getWorkFlowURL();
	data = data + "&ajaxSource=ajaxRequest&_eventId=filterList&mode=embedded";
	$.post(url,data,function(data){
		$(mainContentDiv).empty().html(data);
		var type = $("#docType").val();
		var docStatus = $("#docStatus").val();
		var wfStatus = $("#docWfStatus").val();
		$("#docType").val(type);
		$("#docStatus").val(docStatus);
		$("#docWfStatus").val(wfStatus);
		$.unblockUI(); 
	});
}